<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>攻坚任务</title>
    <%@ include file="/WEB-INF/views/modules/commons/head.jsp" %>
    <%--多选css--%>
    <link rel="stylesheet" href="<s:url value="/assets/web/js/multiSelect/css/fselect.css"></s:url>">
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>

    <style>
        /*转成省略号*/
        /*.ui-jqgrid tr.jqgrow td { text-overflow : ellipsis; }*/
        .ui-jqgrid tr.jqgrow td {
            white-space: normal !important;
            height: 35px;
            vertical-align: text-top;
            padding-top: 2px;
        }

        .nav {
            margin-left: 0;
        }

        .nav > li > a:focus, .nav > li > a:hover {
            text-decoration: none;
            background-color: #33CCFF !important;
        }

        #gview_gridTable .ui-jqgrid-bdiv {
            max-height: 450px;
        !important;
        }

        #main-container {
            padding-top: 45px;
            position: relative;
            height: calc(100%);
            margin-left: 17.5%;
            margin-top: 60px;
        }

        .modal-dialog {
            z-index: 9999999;
        }

        @media (min-width: 768px) {
            .modal-content {
                -webkit-box-shadow: 0 5px 15px rgba(0, 0, 0, .5);
                box-shadow: 0 -2px 20px rgba(0, 0, 0, .5) !important;
            }
        }

        td {
            cursor: default;
        }

        /*个数*/
        #banjieNum {
            background-color: #d15b47 !important;
            margin: 10px 3px;
            color: #fff;
            position: absolute;
            top: -15px;
            right: -17px;
        }

        .search-row {
            margin-left: 7px !important;
        }

    </style>
</head>
<body class="bgcolor">
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>
<%@ include file="/WEB-INF/views/modules/commons/nav.jsp" %>
<%@ include file="/WEB-INF/views/modules/commons/menu.jsp" %>


<!-- /section:basics/navbar.layout -->
<table></table>
<div class="main-container" id="main-container">
    <%--搜索查询--%>
    <div class="row search-row">
        <div class="col-xs-2">
            <input type="text" class="form-control" id="searchWord" placeholder="请输入要搜索的关键词">
        </div>
        <div class="col-xs-6" style="right: 23px;">
            <button class="btn btn-large btn-primary" id="query">搜索</button>
            <button class="btn btn-large btn-warning" id="feedback">待办结任务</button>
            <button class="btn btn-large btn-primary" id="approvalList">待审核任务</button>
            <button class="btn btn-large btn-success" id="approvaledList">已审核任务</button>
        </div>
    </div>
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <div class="pull-left">
                            <%-- <shiro:hasPermission name="modules:sys:huashu:query"></shiro:hasPermission> --%>
                            <%--<button class="btn btn-sm btn-info" id="feedbackToTack">反馈攻坚</button>--%>
                            <%--<button class="btn btn-sm btn-success" id="exportTackTable">导出攻坚任务</button>--%>
                            <%--<button class="btn btn-sm btn-warning" id="feedback">待办结任务</button>--%>
                            <%--<button class="btn btn-sm btn-primary" id="approvalList">待审核任务</button>--%>
                            <%--<button class="btn btn-sm btn-success" id="approvaledList">已审核任务</button>--%>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
                <div class="row" style="margin-left: 2px;">
                    * 双击列表可查看反馈详情
                </div>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>


</div><!-- /.main-container -->
</div>
<!-- footer -->
<script src="<s:url value="/assets/web/js/jquery.min.js?v=2.1.4"></s:url>"></script>
<%--公用js--%>
<script src="<s:url value="/assets/web/js/commo.js"></s:url>"></script>
<link rel="stylesheet" href="<s:url value="/assets/web/css/login/bootstrap.min.css?v=3.3.6"></s:url>">
<script src="<s:url value="/assets/web/js/jqpaginator.min.js"></s:url>"></script>
<script src="<s:url value="/assets/web/js/baseAPI.js"></s:url>"></script>
<%--多选js--%>
<script src="<s:url value="/assets/web/js/multiSelect/js/fselect.js"></s:url>"></script>
<script src="<s:url value="/assets/web/common/bootstrapvalidator/dist/js/bootstrapValidator.js"></s:url>"></script>
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<!-- dialog -->
<%@ include file="/WEB-INF/views/include/dialog.jsp" %>


<script type="text/javascript">
    //基本路径
    var baseUrl = "<s:url value="/taskToTack"></s:url>/";
    //jqgrid的表格高度
    var height = 320;
    //jqgrid表格行头的中文
    var colNames = ['督查事项详情', '任务阶段', '逾期天数', '任务结果',
        '督查组别', '督查组成员', '督查组手机号', '责任单位', '责任单位经办人', '经办人手机号',
        '项目名称', '攻坚任务类别', '督查任务类别',
        '任务状态', '任务名称',
        '计划开始时间', '计划结束时间', '创建日期', '创建时间',
        '节点ID', '节点名称', '任务时间',
        '开始日期', '结束日期', '督查单位得分', '责任单位得分', '节点详情', '到期日期',
        '响应时间', '责任单位结果', '督查组结果',
        '是否反馈攻坚', '涉及部门', '任务单号', ''
    ];

    var colModel = [
        {name: 'taskContent', index: 'taskContent', width: 200, editable: true},
        {
            name: 'tasktimes',
            index: 'tasktimes',
            width: 90,
            editable: true,
            formatter: taskTimesFmatter,
            cellattr: colorSet
        },
        {
            name: 'overdueDays',
            index: 'overdueDays',
            width: 68,
            editable: true,
            formatter: overdueDaysFmatter /*, cellattr: overdueDaysColor*/
        },
        {
            name: 'taskResult',
            index: 'taskResult',
            width: 80,
            editable: true,
            formatter: taskResultFmatter,
            cellattr: addCellAttr1
        },
        {name: 'groupType', index: 'groupType', width: 100, editable: true, formatter: groupTypeFmatter},
        {name: 'inspectors', index: 'inspectors', width: 100, editable: true, formatter: inspectorsFmatter},
        {name: 'phones', index: 'phones', width: 110, editable: true, formatter: phonesFmatter},
        {name: 'resDept', index: 'resDept', width: 100, editable: true},
        {name: 'operatorUser', index: 'operatorUser', width: 116, editable: true},
        {name: 'operatorPhone', index: 'operatorPhone', width: 110, editable: true},
        {name: 'projectName', index: 'projectName', width: 150, editable: true},
        {name: 'tackTaskType', index: 'tackTaskType', width: 100, editable: true},
        {name: 'taskjobType', index: 'taskjobType', width: 100, editable: true},
        {name: 'aaa001', index: 'aaa001', width: 68, editable: true, formatter: aa10Fmatter, cellattr: addCellAttr},
        {name: 'taskName', index: 'taskName', width: 200, editable: true},
        {name: 'planStartDate', index: 'planStartDate', width: 100, editable: true, cellattr: addCellAttrToTime},
        {name: 'planEndDate', index: 'planEndDate', width: 100, editable: true, cellattr: addCellAttrToTime},
        {name: 'createDate', index: 'createDate', width: 80, editable: true},
        {name: 'createTime', index: 'createTime', width: 80, editable: true},
        {name: 'nodeId', index: 'nodeId', width: 80, editable: true},
        {name: 'nodeName', index: 'nodeName', width: 200, editable: true},
        {name: 'taskDate', index: 'taskDate', width: 68, editable: true, formatter: taskDateFmatter},
        {name: 'startDate', index: 'startDate', width: 80, editable: true},
        {name: 'endDate', index: 'endDate', width: 80, editable: true},
        {name: 'supervisionScore', index: 'supervisionScore', width: 100, editable: true},
        {name: 'respScore', index: 'respScore', width: 100, editable: true},
        {name: 'taskName', index: 'taskName', width: 200, editable: true},
        {name: 'planEndDate', index: 'planEndDate', width: 80, editable: true},
        {name: 'responseTime', index: 'responseTime', width: 80, editable: true},
        {name: 'respResult', index: 'respResult', width: 100, editable: true, formatter: respResultFmatter},
        {
            name: 'supervisionResult',
            index: 'supervisionResult',
            width: 100,
            editable: true,
            formatter: respResultFmatter
        },
        {
            name: 'isfeedbackToTack',
            index: 'isfeedbackToTack',
            width: 100,
            editable: true,
            formatter: isfeedbackToTackFmatter
        },
        {name: 'involveUnit', index: 'involveUnit', width: 160, editable: true},
        {name: 'sysId', index: 'sysId', width: 160, editable: true, key: true},
        {name: 'tackFlag', index: 'tackFlag', width: 60, hidden: true},
    ];

    //jqgrid的具体执行方法
    jqgrid({
        autoScroll: false,
        shrinkToFit: false,
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        onSelectRow: function (rowid, status) {
            if (!status) {
                gridRemoveSelect(rowid);
            } else {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowid) {
                        flag = true;
                        continue;
                    }
                }
                if (!flag) {
                    gridAddSelect(rowid);
                }
            }
        },
        gridComplete: function () {
            var rowIds = jQuery("#gridTable").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowIds[k]) {
                        flag = true;
                        continue;
                    }
                }
                if (flag && flag == true) {
                    jQuery("#gridTable").setSelection(rowIds[k], true);
                }
            }
        }
    });
    //清空选中行
    $("#cancelChecked").click(function () {
        $("#gridTable").jqGrid('resetSelection');
        rowids = [];
    });
    var rowids = [];//选中行id
    /**
     * 取消选中
     */
    function gridRemoveSelect(rowid) {
        rowids.remove(rowid);
    }

    /**
     * 添加选中
     */
    function gridAddSelect(rowid) {
        rowids.push(rowid);
    }

    /**
     * 重写Array
     */
    Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };
    /**
     * 重写Array
     */
    Array.prototype.indexOf = function (val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };
    //开启冻结列
    $("#gridTable").jqGrid('setFrozenColumns');
    //加载查询对话框
    $("#queryDialog").load(getUrl("filter"));

    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }

    var exportData = '';
    //显示查询对话框
    var queryDialog = $("#queryDialog");
    $("#taskToTack").click(function () {
        window.location.href = '/taskToTack';
    });
    //返回督查
    /*$("#back").click(function () {
        window.location.href = '/missions';
    });*/

    function colorSet() {
        return "style='color:#ff0000'";
    }

    function overdueDaysFmatter(cellvalue) {
        if (cellvalue != null) {
            return cellvalue + "天";
        } else {
            return "——";
        }
    }

    $(function () {
        //不同用户显示不通按钮
        var userType = ${user.branchType};
        var userRole = "${user.role}";
        if (userRole == "责任人") {
        } else {
            if (userType == "4") {
            }
            if (userType == "1") {
            }
            if (userType == "0") {
            }
            //管理员菜单
            if (userType == "2") {
            }
        }
    });

    //最新搜索
    $("#query").click(function () {
        var url = '/taskToTack';
        var searchWord = $("#searchWord").val();
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {'searchWord': searchWord}, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });

    /**反馈攻坚
     */
    $("#feedbackToTack").click(function () {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "反馈攻坚",
            dialogUrl: getUrl("feedbackToTack"),
            dialogFoot: '<button id="submit" type="button" class="btn btn-primary" onclick="Restartedit()"  >确定</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    });

    $("#exportTackTable").click(function () {
        alert("暂无攻坚任务");
    });

    function taskResultFmatter(cellvalue) {
        if (cellvalue == '0') {
            return "未完成";
        } else if (cellvalue == '1') {
            return "已完成";
        } else if (cellvalue == '3') {
            return "已考核";
        } else if (cellvalue == '4') {
            return "超时完成";
        }
    }


    //待反馈按钮
    $("#feedback").click(function () {
        var url = '/taskToTack';
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {'taskResult': "", 'messageFlag': "", 'valid': "", 'tackFlag': "1"}, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });
    //待审核列表
    $("#approvalList").click(function () {
        var url = '/taskToTack';
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {'taskResult': "", 'messageFlag': "", 'valid': "", 'tackFlag': "2"}, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
        var userType = ${user.branchType};
        if (userType == "2") {
        }
    });

    //已审核列表
    $("#approvaledList").click(function () {
        var url = '/taskToTack';
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {'taskResult': "", 'messageFlag': "", 'valid': "", 'tackFlag': "3"}, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });

    /**
     * ---------------------催办记录提交---------------
     * */
    //执行更新操作
    function cuiBanEdit() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("createTaskLog"),
            tableId: "#gridTable",
            successMessage: "操作成功",
            successTitle: '操作对话框',
            //failMessage: '更新失败',
            failTitle: '消息对话框'
        });
        //倒计时
        var btn = document.getElementById("submit");
        btn.disabled = true;
        countdown(5);
    }

    /**
     * --------------完成情况记录提交事件 recordEdit ----------
     */
    function recordEdit() {
        console.log("催办记录")
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("createRespRecord"),
            tableId: "#gridTable",
            successMessage: "操作成功",
            successTitle: '操作对话框',
            //failMessage: '更新失败',
            failTitle: '消息对话框'
        });
        //倒计时
        var btn = document.getElementById("submit");
        btn.disabled = true
        countdown(5);
    }

    /**
     *-------------------------重新开始督查任务-----------------------
     */
    function Restartedit() {
        console.log("更新操作")
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("rebuildjob"),
            tableId: "#gridTable",
            successMessage: "操作成功",
            successTitle: '操作对话框',
            //failMessage: '更新失败',
            failTitle: '消息对话框'
        });
        //倒计时
        var btn = document.getElementById("submit");
        btn.disabled = true
        countdown(5);
    }

    //执行更新操作
    function addTackLogBtn() {
        console.log("添加反馈日志")
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("addTackLog"),
            tableId: "#gridTable",
            successMessage: "添加成功",
            successTitle: '操作对话框',
            //failMessage: '更新失败',
            failTitle: '消息对话框'
        });
        //倒计时
        // var btn = document.getElementById("submit");
        // btn.disabled = true
        // countdown(5);
    }


    //执行办结操作
    function finishTackBtn() {
        console.log("更新办结操作")
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("finishTack"),
            tableId: "#gridTable",
            successMessage: "提交成功",
            successTitle: '操作对话框',
            //failMessage: '更新失败',
            failTitle: '消息对话框'
        });
        //倒计时
        // var btn = document.getElementById("submit");
        // btn.disabled = true
        // countdown(5);
    }

    //执行审核操作
    function approvalBtn() {
        console.log("更新办结操作")
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("approval"),
            tableId: "#gridTable",
            successMessage: "提交成功",
            successTitle: '操作对话框',
            //failMessage: '更新失败',
            failTitle: '消息对话框'
        });
        //倒计时
        var btn = document.getElementById("submit");
        btn.disabled = true
        countdown(5);
    }


    $("#approval").click(function () {
        approvalView();
    });

    //审批攻坚任务
    function approvalView() {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "审批攻坚任务",
            dialogUrl: getUrl("approval"),
            dialogFoot: '<button id="submit" type="button" class="btn btn-primary" onclick="approvalBtn()" >提交审核</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    }


    $("#finishTack").click(function () {
        finishTackView();
    });

    //办结任务
    function finishTackView() {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "办结任务",
            dialogUrl: getUrl("finishTack"),
            dialogFoot: '<button id="submit" type="button" class="btn btn-primary" onclick="finishTackBtn()" >确认</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    }


    /**
     * 双击显示
     */
    $("#gridTable").dblclick(function (e) {
        showLogView();
    });

    //显示编辑对话框(双击显示)
    function showLogView() {
        var rowId = $('#gridTable').jqGrid('getGridParam', "selrow");
        var rowData = $("#gridTable").jqGrid('getRowData', rowId);
        loadDialog({
            dialogTitle: '攻坚反馈日志',
            dialogUrl: baseUrl + "readLog/" + rowId,
            dialogFoot: '<button type="button" class="btn btn-default" data-dismiss="modal" id="showDetail" >关闭</button>'
        });
    }


    function aa10Fmatter(cellvalue, options, rowObject) {
        if (cellvalue == "1") {
            return "有效任务";
        } else if (cellvalue == "0") {
            return "失效任务";
        }
    }

    function taskDateFmatter(cellvalue) {

        if (cellvalue != null) {
            return cellvalue + "天";
        } else {
            return "--天";
        }
    }

    function respResultFmatter(cellvalue) {
        if (cellvalue == '0') {
            return "认定未完成";
        } else if (cellvalue == '1') {
            return "认定已完成";
        }
    }

    function isfeedbackToTackFmatter(cellvalue) {
        if (cellvalue == null) {
            return "未反馈";
        } else if (cellvalue == '0') {
            return "未反馈";
        } else if (cellvalue == '1') {
            return "反馈";
        }
    }

    function taskTimesFmatter(cellvalue, options, rowObject) {
        if (rowObject.tackFlag == '1') {
            return "攻坚(待反馈)";
        } else if (rowObject.tackFlag == '2') {
            return "攻坚(待审核)";
        } else if (rowObject.tackFlag == '3') {
            return "攻坚(已审核)";
        }

    }

    function addCellAttr(rowId, val, rawObject, cm, rdata) {
        if (rawObject.aaa001 == "0") {
            return "style='color:red'";
        }
    }

    function addCellAttrToTime(rowId, val, rawObject, cm, rdata) {
        return "style='color:blue'";
    }

    function slices(strings) {
        return (strings.slice(strings.length - 1) === ',') ? strings.slice(0, -1) : strings;
    }

    function groupTypeFmatter(cellvalue, options, rowObject) {
        return slices(cellvalue);
    }

    function inspectorsFmatter(cellvalue, options, rowObject) {
        return slices(cellvalue);
    }

    function phonesFmatter(cellvalue, options, rowObject) {
        return slices(cellvalue);
    }

    function addCellAttr1(rowId, val, rawObject, cm, rdata) {
        if (rawObject.aaa001 == "0") {
            if (rawObject.taskResult == "0") {
                return "style='color:red'";
            } else {
                return "style='color:#f0ad4e'";
            }
        } else {
            if (rawObject.taskResult == "0") {
                return "style='color:red'";
            }
        }
    }

    //办结任务——返回
    function tackLog_back() {
        var rowId = $('#gridTable').jqGrid('getGridParam', "selrow");
        var rowData = $("#gridTable").jqGrid('getRowData', rowId);
        loadDialog({
            dialogTitle: '攻坚反馈日志',
            dialogUrl: baseUrl + "readLog/" + rowId,
            dialogFoot: '<button type="button" class="btn btn-default" data-dismiss="modal" id="showDetail" >关闭</button>'
        });
    }

    $(function () {
        $.ajax({
            type: "GET",
            url: "/taskToTack/getTackTaskEachNums",
            dataType: "json",
            data: {},
            success: function (model) {
                if (model.code == "200") {
                    console.log(model)
                    $("#feedback").html("待办结任务（" + model.data.num1 + ")");
                    $("#approvalList").html("待审核任务（" + model.data.num2 + ")");
                    $("#approvaledList").html("已审核任务（" + model.data.num3 + ")");
                }
            },
            error: function (model) {
            }
        });
    })

</script>

</body>
</html>